package com.example.module_car.ui.addcar

import android.content.Intent
import androidx.activity.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.lib_common.base.BaseActivity
import com.example.module_car.R
import com.example.module_car.adapter.ProvincesAdapter
import com.example.module_car.databinding.ActivityAddCarBinding
import com.example.module_car.ui.play.PayActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AddCarActivity : BaseActivity<AddCarViewModel,ActivityAddCarBinding>() {
    override val mLayoutResId: Int get() = R.layout.activity_add_car
    val mViewModel : AddCarViewModel by viewModels()
    lateinit var mProvincesAdapter: ProvincesAdapter

    override fun initView() {
        super.initView()
    }

    override fun initData() {
        super.initData()
        mViewModel.getProvincesList()
        //适配器初始化
        mProvincesAdapter = ProvincesAdapter(){
            mBinding.tvProvince.text = it
        }
        mViewModel.mProvincesList.observe(this){
            mProvincesAdapter.setList(it)
        }
        mBinding.gridView.adapter = mProvincesAdapter
        mBinding.gridView.layoutManager = GridLayoutManager(this, 7)

        mBinding.addButton.setOnClickListener {
            val intent = Intent(this,PayActivity::class.java).putExtra("provinces","${mBinding.tvProvince.text}"+mBinding.textInput.text)
            startActivity(intent)
            finish()
        }
    }

}